/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.invoice.controller;

import javax.validation.Valid;
import com.google.common.collect.Lists;
import com.jeeplus.core.query.QueryWrapperGenerator;
import com.jeeplus.aop.logging.annotation.ApiLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.invoice.invoice.service.dto.YxfpInvoiceDTO;
import com.jeeplus.invoice.invoice.service.mapstruct.YxfpInvoiceWrapper;
import com.jeeplus.invoice.invoice.service.YxfpInvoiceService;

/**
 *  发票管理Controller
 * @author 张如利
 * @version 2022-02-16
 */

@Api(tags =" 发票管理")
@RestController
@RequestMapping(value = "/invoice/invoice/yxfpInvoice")
public class YxfpInvoiceController {

	@Autowired
	private YxfpInvoiceService yxfpInvoiceService;

	@Autowired
	private YxfpInvoiceWrapper yxfpInvoiceWrapper;

	/**
	 *  发票管理列表数据
	 */
	@ApiLog("查询 发票管理列表数据")
	@ApiOperation(value = "查询 发票管理列表数据")
	@PreAuthorize("hasAuthority('invoice:invoice:yxfpInvoice:list')")
	@GetMapping("list")
	public ResponseEntity<IPage<YxfpInvoiceDTO>> list(YxfpInvoiceDTO yxfpInvoiceDTO, Page<YxfpInvoiceDTO> page) throws Exception {
		QueryWrapper queryWrapper = QueryWrapperGenerator.buildQueryCondition (yxfpInvoiceDTO, YxfpInvoiceDTO.class);
		IPage<YxfpInvoiceDTO> result = yxfpInvoiceService.findPage (page, queryWrapper);
		return ResponseEntity.ok (result);
	}


	/**
	 * 根据Id获取 发票管理数据
	 */
	@ApiLog("根据Id获取 发票管理数据")
	@ApiOperation(value = "根据Id获取 发票管理数据")
	@PreAuthorize("hasAnyAuthority('invoice:invoice:yxfpInvoice:view','invoice:invoice:yxfpInvoice:add','invoice:invoice:yxfpInvoice:edit')")
	@GetMapping("queryById")
	public ResponseEntity<YxfpInvoiceDTO> queryById(String id) {
		return ResponseEntity.ok ( yxfpInvoiceService.findById ( id ) );
	}

	/**
	 * 保存 发票管理
	 */
	@ApiLog("保存 发票管理")
	@ApiOperation(value = "保存 发票管理")
	@PreAuthorize("hasAnyAuthority('invoice:invoice:yxfpInvoice:add','invoice:invoice:yxfpInvoice:edit')")
	@PostMapping("save")
	public  ResponseEntity <String> save(@Valid @RequestBody YxfpInvoiceDTO yxfpInvoiceDTO) {
		//新增或编辑表单保存
		yxfpInvoiceService.saveOrUpdate (yxfpInvoiceWrapper.toEntity (yxfpInvoiceDTO));
        return ResponseEntity.ok ( "保存 发票管理成功" );
	}


	/**
	 * 删除 发票管理
	 */
	@ApiLog("删除 发票管理")
	@ApiOperation(value = "删除 发票管理")
	@PreAuthorize("hasAuthority('invoice:invoice:yxfpInvoice:del')")
	@DeleteMapping("delete")
	public ResponseEntity <String> delete(String ids) {
		String idArray[] = ids.split(",");
        yxfpInvoiceService.removeByIds ( Lists.newArrayList ( idArray ) );
		return ResponseEntity.ok( "删除 发票管理成功" );
	}

}
